#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <float.h>

#define int128_t __int128_t

/* 编译器生成的汇编代码
	mov	rax, rdi
	imul rsi
	shrd rax, rdx, 62
	ret
*/
int64_t mul64(int64_t a, int64_t b) 
{
    int128_t r=(int128_t)a * b;
    return (int64_t)(r >> 62);
}

void test_mul64()
{
    int64_t  i,j,r;
    int t;
    printf("\nrun %s()\n",__func__);
    printf("i=?"); t=scanf("%ld",&i);
    printf("j=?"); t=scanf("%ld",&j);
    r = mul64(i,j);
    printf("i=%ld,j=%ld,r=%ld\n",i,j,r);
}

void int64_assign()
{
    printf("\nrun %s()\n",__func__);
    int64_t x=-1;
    unsigned char* p= (unsigned char*)(&x);
    printf("int64(-1)={");
    for (int i=0;i<8;i++)
    {
        printf("0x%02x,", p[i]);
    }
    printf("}\n");
}

int main(int argc, char* argv[])
{
    test_mul64();
    int64_assign();
    return 0;
}
